home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / managers / layoutClasses / PriorityQueue.as
Text File  |  2009-02-12  |  6KB  |  211 lines

  1. package mx.managers.layoutClasses
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import mx.core.IChildList;
  6.    import mx.core.IRawChildrenContainer;
  7.    import mx.core.mx_internal;
  8.    import mx.managers.ILayoutManagerClient;
  9.    
  10.    use namespace mx_internal;
  11.    
  12.    public class PriorityQueue
  13.    {
  14.       
  15.       mx_internal static const VERSION:String = "3.0.0.0";
  16.        
  17.       
  18.       private var maxPriority:int = -1;
  19.       
  20.       private var arrayOfArrays:Array;
  21.       
  22.       private var minPriority:int = 0;
  23.       
  24.       public function PriorityQueue()
  25.       {
  26.          arrayOfArrays = [];
  27.          super();
  28.       }
  29.       
  30.       public function addObject(param1:Object, param2:int) : void
  31.       {
  32.          if(!arrayOfArrays[param2])
  33.          {
  34.             arrayOfArrays[param2] = [];
  35.          }
  36.          arrayOfArrays[param2].push(param1);
  37.          if(maxPriority < minPriority)
  38.          {
  39.             minPriority = maxPriority = param2;
  40.          }
  41.          else
  42.          {
  43.             if(param2 < minPriority)
  44.             {
  45.                minPriority = param2;
  46.             }
  47.             if(param2 > maxPriority)
  48.             {
  49.                maxPriority = param2;
  50.             }
  51.          }
  52.       }
  53.       
  54.       public function removeSmallest() : Object
  55.       {
  56.          var _loc1_:Object = null;
  57.          if(minPriority <= maxPriority)
  58.          {
  59.             while(!arrayOfArrays[minPriority] || arrayOfArrays[minPriority].length == 0)
  60.             {
  61.                ++minPriority;
  62.                if(minPriority > maxPriority)
  63.                {
  64.                   return null;
  65.                }
  66.             }
  67.             _loc1_ = arrayOfArrays[minPriority].shift();
  68.             while(!arrayOfArrays[minPriority] || arrayOfArrays[minPriority].length == 0)
  69.             {
  70.                ++minPriority;
  71.                if(minPriority > maxPriority)
  72.                {
  73.                   break;
  74.                }
  75.             }
  76.          }
  77.          return _loc1_;
  78.       }
  79.       
  80.       public function removeLargestChild(param1:ILayoutManagerClient) : Object
  81.       {
  82.          var _loc5_:int = 0;
  83.          var _loc2_:Object = null;
  84.          var _loc3_:int = maxPriority;
  85.          var _loc4_:int = param1.nestLevel;
  86.          while(_loc4_ <= _loc3_)
  87.          {
  88.             if(arrayOfArrays[_loc3_] && arrayOfArrays[_loc3_].length > 0)
  89.             {
  90.                _loc5_ = 0;
  91.                while(_loc5_ < arrayOfArrays[_loc3_].length)
  92.                {
  93.                   if(contains(DisplayObject(param1),arrayOfArrays[_loc3_][_loc5_]))
  94.                   {
  95.                      _loc2_ = arrayOfArrays[_loc3_][_loc5_];
  96.                      arrayOfArrays[_loc3_].splice(_loc5_,1);
  97.                      return _loc2_;
  98.                   }
  99.                   _loc5_++;
  100.                }
  101.                _loc3_--;
  102.             }
  103.             else
  104.             {
  105.                if(_loc3_ == maxPriority)
  106.                {
  107.                   --maxPriority;
  108.                }
  109.                _loc3_--;
  110.                if(_loc3_ < _loc4_)
  111.                {
  112.                   break;
  113.                }
  114.             }
  115.          }
  116.          return _loc2_;
  117.       }
  118.       
  119.       public function isEmpty() : Boolean
  120.       {
  121.          return minPriority > maxPriority;
  122.       }
  123.       
  124.       public function removeLargest() : Object
  125.       {
  126.          var _loc1_:Object = null;
  127.          if(minPriority <= maxPriority)
  128.          {
  129.             while(!arrayOfArrays[maxPriority] || arrayOfArrays[maxPriority].length == 0)
  130.             {
  131.                --maxPriority;
  132.                if(maxPriority < minPriority)
  133.                {
  134.                   return null;
  135.                }
  136.             }
  137.             _loc1_ = arrayOfArrays[maxPriority].shift();
  138.             while(!arrayOfArrays[maxPriority] || arrayOfArrays[maxPriority].length == 0)
  139.             {
  140.                --maxPriority;
  141.                if(maxPriority < minPriority)
  142.                {
  143.                   break;
  144.                }
  145.             }
  146.          }
  147.          return _loc1_;
  148.       }
  149.       
  150.       public function removeSmallestChild(param1:ILayoutManagerClient) : Object
  151.       {
  152.          var _loc4_:int = 0;
  153.          var _loc2_:Object = null;
  154.          var _loc3_:int = param1.nestLevel;
  155.          while(_loc3_ <= maxPriority)
  156.          {
  157.             if(arrayOfArrays[_loc3_] && arrayOfArrays[_loc3_].length > 0)
  158.             {
  159.                _loc4_ = 0;
  160.                while(_loc4_ < arrayOfArrays[_loc3_].length)
  161.                {
  162.                   if(contains(DisplayObject(param1),arrayOfArrays[_loc3_][_loc4_]))
  163.                   {
  164.                      _loc2_ = arrayOfArrays[_loc3_][_loc4_];
  165.                      arrayOfArrays[_loc3_].splice(_loc4_,1);
  166.                      return _loc2_;
  167.                   }
  168.                   _loc4_++;
  169.                }
  170.                _loc3_++;
  171.             }
  172.             else
  173.             {
  174.                if(_loc3_ == minPriority)
  175.                {
  176.                   ++minPriority;
  177.                }
  178.                _loc3_++;
  179.                if(_loc3_ > maxPriority)
  180.                {
  181.                   break;
  182.                }
  183.             }
  184.          }
  185.          return _loc2_;
  186.       }
  187.       
  188.       public function removeAll() : void
  189.       {
  190.          arrayOfArrays.splice(0);
  191.          minPriority = 0;
  192.          maxPriority = -1;
  193.       }
  194.       
  195.       private function contains(param1:DisplayObject, param2:DisplayObject) : Boolean
  196.       {
  197.          var _loc3_:IChildList = null;
  198.          if(param1 is IRawChildrenContainer)
  199.          {
  200.             _loc3_ = IRawChildrenContainer(param1).rawChildren;
  201.             return _loc3_.contains(param2);
  202.          }
  203.          if(param1 is DisplayObjectContainer)
  204.          {
  205.             return DisplayObjectContainer(param1).contains(param2);
  206.          }
  207.          return param1 == param2;
  208.       }
  209.    }
  210. }
  211.